# -*- coding: utf-8 -*-
"""
Created on Mon Jan 06 14:47:05 2014

@author: Maxim
"""
from numpy import array,append
import field
import climbDescent
import aircraft
import mission

class MissionResult:
    def __init__(self):
        self.name = list()
        self.segTime = list()
        self.segFuelBurned = list()
        self.segDistance = list()
    
    def add(self,name,time,fuelBurned,distance):
        self.name.append(name)
        self.segTime.append(time)
        self.segFuelBurned.append(fuelBurned)
        self.segDistance.append(distance)
        self._summarize()
    
    def _summarize(self):
        self.totalTime = sum(self.segTime)
        self.totalFuel = sum(self.segFuelBurned)
        self.totalDistance = sum(self.segDistance)


def profile1(aircraft, fieldAltitude, cruiseAltitude, cruisePowerSetting):
    takeoff, landing = field.run_field(aircraft,fieldAltitude)
    aircraft.mass.fuel.set_fuel_mass_burned(takeoff.fuelBurned)
    aircraft.mass.update_total()
    
    climb = climbDescent.climb_simulation(aircraft,fieldAltitude,cruiseAltitude,nSeg=10)
    aircraft.mass.fuel.set_fuel_mass_burned(climb.fuelBurned)
    aircraft.mass.update_total()
    
    v = aircraft.designGoals.designSpeed
    rslt = aircraft.analyze_aero_trim(aircraft.designGoals.designSpeed,cruiseAltitude)
    aircraft.analysis.aerodynamics.update(v,1.225)
    k        =rslt.k
    Cd0      =aircraft.get_drag(v,cruiseAltitude)
    S        =aircraft.wing.area
    mass = aircraft.mass.totalMass
    bi       =mission.basicInput(cruiseAltitude,0,Cd0,k,S,mass,2.2)
    tm       =aircraft.analysis.thrust
    
    crs = mission.Cruise()
    crs._init_cruise(aircraft)
    crs.thrustModule = tm
    crs.basicInput = bi

    cruise = crs.get_range_at_power_setting(aircraft.mass.fuel(),10.,cruiseAltitude,cruisePowerSetting)

    takeoff.display()
    landing.display()
    climb.display()
    cruise.display()

def run_test1():
    ac = aircraft.load('V0510')
    profile1(ac,0,2000,75.0)

if __name__=="__main__":
    run_test1()